home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 3 / Cream of the Crop 3.iso / comm / wnos5src.zip / TTYLINK.C < prev    next >
Text File  |  1993-10-13  |  3KB  |  134 lines

  1. #include <stdio.h>
  2. #include <dos.h>
  3. #include <conio.h>
  4. #include <time.h>
  5. #include "global.h"
  6. #include "mbuf.h"
  7. #include "socket.h"
  8. #include "telnet.h"
  9. #include "session.h"
  10. #include "proc.h"
  11. #include "tty.h"
  12. #include "mailbox.h"
  13. #include "commands.h"
  14. #include "cmdparse.h"
  15. #include "netuser.h"
  16.  
  17. static char Motd[85];
  18. int Attended = TRUE;
  19. static int16 Bell = 2;
  20.  
  21. int
  22. dobell(int argc,char **argv,void *p)
  23. {
  24.     return setintrc(&Bell,"Bell",argc,argv,0,10);
  25. }
  26.  
  27. /* if flag is set - restrict ax25, telnet and maybe other sessions */
  28. int
  29. doattended(int argc,char **argv,void *p)
  30. {
  31.     return setbool(&Attended,"Attended",argc,argv);
  32. }
  33.  
  34. int
  35. domotd(int argc,char **argv,void *p)
  36. {
  37.     int i;
  38.  
  39.     if(argc < 2) {
  40.         if(Motd[0] != '\0')
  41.             tputs(Motd);
  42.     } else {
  43.         Motd[0] = '\0';
  44.  
  45.         for(i = 1; i < argc; i++) {
  46.             strcat(Motd,argv[i]);
  47.             if(strlen(Motd) > 80)
  48.                 break;
  49.             strcat(Motd," ");
  50.         }
  51.         if(strlen(Motd) > 2)
  52.             strcat(Motd,"\n\0");
  53.         else
  54.             Motd[0] = '\0';
  55.     }
  56.     return 0;
  57. }
  58.  
  59. /* This function handles all incoming "chat" sessions, be they TCP,
  60.  * NET/ROM or AX.25
  61.  */
  62. void
  63. ttylhandle(int s,void *t,void *p)
  64. {
  65.     struct session *sp;
  66.     char addr[MAXSOCKSIZE];
  67.     struct telnet tn;
  68.     char *cp, *cp1;
  69.     int len = MAXSOCKSIZE, type = (int) t;
  70.  
  71.     sockowner(s,Curproc);    /* We own it now */
  72.     sockmode(s,SOCK_ASCII);
  73.  
  74.     /* Allocate a session descriptor */
  75.     if((sp = newsession(NULLCHAR,type,SPLIT)) == NULLSESSION) {
  76.         usputs(s,Nosess);
  77.         close_s(s);
  78.         return;
  79.     }
  80.  
  81.     log(s,9983,"%4.4s open",Sestypes[type]);
  82.  
  83.     /* Initialize a Telnet protocol descriptor */
  84.     memset(&tn,0,sizeof(struct telnet));
  85.  
  86.     tn.session = sp;            /* Upward pointer */
  87.     sp->cb.telnet = &tn;        /* Downward pointer */
  88.     sp->s = s;
  89.     sp->proc = Curproc;
  90.  
  91.     getpeername(sp->s,addr,&len);
  92.     cp1 = strxdup(psocket(addr));
  93.  
  94.     if((cp = strchr(cp1,':')) != NULLCHAR) {
  95.         *cp = '\0';
  96.     }
  97.     tprintf("Incoming %s session from %s at %s",
  98.         Sestypes[type],cp1,ctime(&currtime));
  99.  
  100.     if(strcmp(cp1,inet_ntoa(Ip_addr)) == 0) {
  101.         xfree(cp1);
  102.         sp->name = strxdup("Chat");
  103.     } else {
  104.         sp->name = cp1;
  105.     }
  106.  
  107.     if(Attended && Bell) {
  108.         if(Mtasker) {
  109.             putch(7);
  110.         } else {
  111.             int val = Bell;
  112.             
  113.             while(val-- > 0) {
  114.                 sound(320);
  115.                 delay(160);
  116.                 sound(480);
  117.                 delay(160);
  118.                 sound(640);
  119.                 delay(160);
  120.                 nosound();
  121.                 pwait(NULL);
  122.             }
  123.         }
  124.     }
  125.     if(Motd != NULLCHAR) {
  126.         usputs(s,Motd);
  127.     }
  128.     usprintf(s,"%s - I'm %s...\n",Hostname,
  129.         Attended ? "here" : "absent. Pse leave msg");
  130.  
  131.     tnrecv(&tn);
  132. }
  133.  
  134.